﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoxGenerateScript : MonoBehaviour
{
    public GameObject objectPrefab;                   //预制件
    public float timeInterval;                        //生成时间间隔 单位s
    private bool asChildComponent = true;             //是否以子组件形式生成
    private float timeBuffer = 0;                     //缓冲时间计量 当生成的目标含有对应摧毁时调用时会减少
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        timeBuffer += Time.deltaTime;
        if (timeInterval <= timeBuffer)
        {
            timeBuffer = 0;
            GameObject temp = Instantiate(objectPrefab);

            if (asChildComponent)
            {
                temp.transform.parent = this.transform; //设置父物体
            }
            temp.transform.position = this.transform.position;
        }
    }
}
